//
//  LMMainTabbarViewController.m
//  LMDuanZi
//
//  Created by 刘明 on 17/3/8.
//  Copyright © 2017年 刘明. All rights reserved.
//

#import "LMMainTabbarViewController.h"
#import "LMMainNavigationController.h"
#import "LMTabBar.h"
#import "AppDelegate.h"
#import "SQHomeViewController.h"
#import "SQOriginaztionViewController.h"
#import "SQPublishViewController.h"
#import "SQMessageViewController.h"
#import "SQMineViewController.h"


@interface LMMainTabbarViewController ()<LMTabBarDelegate>
@property (nonatomic, strong) UIButton *composeButton;
@end

@implementation LMMainTabbarViewController

#pragma mark - initialition

+ (void)initialize{
    
    [[UITabBar appearance] setTranslucent:NO];
//    [[UITabBar appearance] setBarTintColor:LMRGBFLOATColor(0.97f, 0.97f, 0.97f)];
    
    // 拿到整个导航控制器的外观
    UITabBarItem * item = [UITabBarItem appearance];
    item.titlePositionAdjustment = UIOffsetMake(0, 1.5);
    
    // 普通状态
    NSMutableDictionary * normalAtts = [NSMutableDictionary dictionary];
    normalAtts[NSFontAttributeName] = [UIFont systemFontOfSize:11];
    normalAtts[NSForegroundColorAttributeName] = S_Color_102;
    [item setTitleTextAttributes:normalAtts forState:UIControlStateNormal];
    
    // 选中状态
    NSMutableDictionary *selectAtts = [NSMutableDictionary dictionary];
    selectAtts[NSFontAttributeName] = [UIFont systemFontOfSize:11];
    selectAtts[NSForegroundColorAttributeName] = S_Color_98;
    [item setTitleTextAttributes:selectAtts forState:UIControlStateSelected];

}


#pragma mark - View & LifeCycle

- (void)viewWillLayoutSubviews{
    
    [super viewWillLayoutSubviews];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];

    [self addChildViewControllerWithClassname:[SQHomeViewController description] imageName:@"homepage_18.png" selectedImageName:@"homepage_select18.png" title:@"首页"];
    
    [self addChildViewControllerWithClassname:[SQOriginaztionViewController description] imageName:@"homepage_20.png" selectedImageName:@"homepage_select20.png" title:@"社群"];
    
    [self addChildViewControllerWithClassname:[SQMessageViewController description] imageName:@"homepage_19.png" selectedImageName:@"homepage_select19.png" title:@"消息"];
    [self addChildViewControllerWithClassname:[SQMineViewController description] imageName:@"homepage_21.png" selectedImageName:@"homepage_select21.png" title:@"我的"];
    
    
    LMTabBar *tabbar = [[LMTabBar alloc] init];
    tabbar.tabBarDelegate = self;
    tabbar.tintColor = S_Color_98;
    [self setValue:tabbar forKeyPath:@"tabBar"];

}

#pragma mark - Private

- (void)addChildViewControllerWithClassname:(NSString *)classname
                                  imageName:(NSString *)imageName
                                  selectedImageName:(NSString *)selectedImageName
                                      title:(NSString *)title {
    
    UIViewController *vc = [[NSClassFromString(classname) alloc] init];

    if ([classname isEqualToString:@"SQMessageViewController"]) {
        
        AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
        
        vc = app.msgVC;
    }
    vc.title = title;
    LMMainNavigationController *nav = [[LMMainNavigationController alloc] initWithRootViewController:vc];
    nav.tabBarItem.title = title;
    if ([title isEqualToString:@"消息"]) {
        nav.tabBarItem.tag = 10086;
    }
    nav.tabBarItem.image = [UIImage imageNamed:imageName];
    nav.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImageName]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [self addChildViewController:nav];
}

#pragma mark - Action

- (void)tabBarPlusBtnClick:(LMTabBar *)tabBar{
    
    SQPublishViewController *p = [[SQPublishViewController alloc] init];
    
    [self presentViewController:p animated:YES completion:nil];
    
}

#pragma mark - lazy




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
